$(()=>{
    $.ajax({
        type: 'get',
        url : '/projectdetailsraceTypesamsara/list_racetypeno.do',
        data : {
            racetypeno: getSearchInfo().racetypeno
        },
        dataType : 'json',
        xhrFields : {
            withCredentials: true
        },
        crossDomain: true,
        success: function (data) {
            console.log(data);
            if( data.status == 0 ){
                renderVote(data);
            }
        }
    });
    function  renderVote(data) {
        $('#voteName').html(data.msg);
        let dom = ``;
        for( let item of data.data ){
            dom += `
            <div class="col-sm-6">
                <div class="thumbnail">
                    <img src="${item.coverurl}" style="width:250px;height: 150px">
                    <div class="caption">
                        <h3>${item.projectname}</h3>
                        <p>${item.team}</p>
                        <p style="text-align: right">
                        <span style="float: left">获票数：<strong style="color:#8E1614" >${item.ballot}</strong></span>
                        <a href="javascript:;" class="btn btn-primary voteBtn" data-id="${item.projectno}">投票</a></p>
                    </div>
                </div>
            </div>`
        }
        $('#voteList').html(dom);
        onBtn();
    }

    function onBtn() {
        $('.voteBtn').on('click', function () {
            let id = $(this).attr('data-id');
            $.ajax({
                type: 'post',
                url : '/projectdetailsraceTypesamsara/ballot.do',
                data : {
                    projectno: id
                },
                dataType : 'json',
                xhrFields : {
                    withCredentials: true
                },
                crossDomain: true,
                success: function (data) {
                    if( data.status == 0 ){
                        spop_ok(data.msg);
                    }else{
                        spop_er(data.msg);
                    }
                }
            });
        });
    }
});